package com.erp.auto.controller;

import com.erp.auto.domain.ErpAutoPulishProductProject;
import com.erp.auto.domain.bo.ErpAutoPublishProductProjectBo;
import com.erp.auto.domain.vo.ErpAutoPulishProductProjectVo;
import com.erp.auto.service.IErpAutoPublishProductProjectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.auto.api.domain.ErpAutoPulishProductProjectTask;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.core.utils.oldUtils.StringUtils;
import com.ruoyi.gather.api.domain.dto.AutoQueryInfoDto;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * auto项目获取信息
 */
@RestController
@RequestMapping("/pulishProduct/autoPulishProductProject")
public class ErpAutoPulishProductProjectController {
    @Autowired
    IErpAutoPublishProductProjectService erpAutoPulishProductProjectService;

    /**
     * 根据id查看详情
     */
    @GetMapping("/queryProjectById")
    public R<Object> queryProjectById(String id) {
        return erpAutoPulishProductProjectService.queryProjectById(id);
    }

    /**
     * 编辑计划
     */
    @PostMapping("/editPulishProject")
    public R<Object> editPulishProject(@RequestBody ErpAutoPulishProductProject project) {
        return erpAutoPulishProductProjectService.editPulishProject(project);
    }

    /**
     * 状态变更
     */
    @GetMapping("/editPulishProjectStatus")
    public R<Object> editPulishProjectStatus(String id, Integer status) {
        return erpAutoPulishProductProjectService.editPulishProjectStatus(id, status);
    }

    @PostMapping("/addPulishProductProject")
    public R<Object> addPulishProductProject(@RequestBody ErpAutoPublishProductProjectBo projectBo) {
        return erpAutoPulishProductProjectService.addPulishProductProject(projectBo);
    }

    @GetMapping("/getPulishProductProjectTaskList")
    public R<Object> getPulishProductProjectList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                                 String startTime,
                                                 String endTime,
                                                 Long aeProductId,
                                                 String projectId,
                                                 String status) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<ErpAutoPulishProductProjectTask> pulishProductProjectTaskList = new PageInfo<>(erpAutoPulishProductProjectService.getPulishProductProjectTaskList(aeProductId, projectId, status, startTime, endTime));
        return R.ok(pulishProductProjectTaskList);
    }

    /**
     * 执行计划1.0 跑计划
     */
    @GetMapping("/runPulishProductProjectJob")
    public R<Object> runPulishProductProjectJob() {
        return erpAutoPulishProductProjectService.runPulishProductProjectJob();
    }

    /**
     * 创建今日未创建任务的计划
     * @return
     */
    @GetMapping("/runNotCreatePulishProductProjectJob")
    public R<Object> runNotCreatePulishProductProjectJob() {
        return erpAutoPulishProductProjectService.runNotCreatePulishProductProjectJob();
    }

    /**
     * 重启失败执行计划
     * @return
     */
    @GetMapping("/restartPublishProductProjectJob")
    public R<Object> restartPublishProductProjectJob() {
        return erpAutoPulishProductProjectService.restartPulishProductProjectJob(null, null, null);
    }

    /**
     * 测试执行1688采集版下架计划
     * @return
     */
    @GetMapping("/runlishProductProjectJobByUnshelf")
    public R<Object> runlishProductProjectJobByUnshelf(Long projectId) {
        return erpAutoPulishProductProjectService.runlishProductProjectJobByUnshelf(projectId, 1, 2);
    }

    /**
     * 执行计划1.0 跑计划
     */
    @GetMapping("/runPulishProductProjectJobById")
    public R<Object> runPulishProductProjectJobById(String id) {
        return erpAutoPulishProductProjectService.runPulishProductProjectJobById(id);
    }

    /**
     * 执行计划 根据storeUserName加速跑
     */
    @GetMapping("/runProjectByStoreUserName")
    public R<Object> runProjectByStoreUserName(String storeUserName) {
        return erpAutoPulishProductProjectService.runProjectByStoreUserName(storeUserName);
    }

    /**
     * 调用爬虫创建活动
     * @return
     */
    @GetMapping("/processingProjectGroupAndDiscount")
    public R<Object> processingProjectGroupAndDiscount() {
        return erpAutoPulishProductProjectService.processingProjectGroupAndDiscount();
    }

    /**
     * 同步token
     * @return
     */
    @GetMapping("/synchronizationToken")
    public R<Object> synchronizationToken(String storeUserName) {
        return erpAutoPulishProductProjectService.synchronizationToken(storeUserName);
    }


    @PostMapping("/queryStoreProductNumberByInfo")
    public R<Object> queryStoreProductNumberByInfo(@RequestBody AutoQueryInfoDto dto) {
        return R.ok(erpAutoPulishProductProjectService.queryStoreProductNumberByInfo(dto));
    }

    /**
     * 批量下架后重上计划
     */
    @GetMapping("/unshelfErrorAndCreateTask")
    public R<Object> unshelfErrorAndCreateTask() {
        return erpAutoPulishProductProjectService.unshelfErrorAndCreateTask();
    }

    /**
     * 批量下架后重上计划
     */
    @GetMapping("/unshelfErrorAndCreateTaskNew")
    public R<Object> unshelfErrorAndCreateTaskNew() {
        return erpAutoPulishProductProjectService.unshelfErrorAndCreateTaskNew();
    }

    /**
     * 批量下架后重上计划
     */
    @GetMapping("/unshelfErrorAndCreateTaskAgain")
    public R<Object> unshelfErrorAndCreateTaskAgain() {
        return erpAutoPulishProductProjectService.unshelfErrorAndCreateTaskAgain();
    }


    /**
     * 重新创建活动
     */
    @GetMapping("/createNewProjectActivityByStoreId")
    public R<Object> createNewProjectActivityByStoreId(Long storeId) {
        return erpAutoPulishProductProjectService.createNewProjectActivityByStoreId(storeId);
    }

    /**
     * 换绑Erp后修改上架计划定价模版 erp_seller_store_price_template
     */
    @GetMapping("/changeBindingProjectPriceTemplate")
    public R<Object> changeBindingProdjectPriceTemplate(Long projectId) {
        return erpAutoPulishProductProjectService.changeBindingProdjectPriceTemplate(projectId);
    }


}
